{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "from numpy import genfromtxt\n",
    "from sklearn import linear_model\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[     nan      nan      nan      nan      nan      nan      nan      nan]\n",
      " [     nan   83.     234.289  235.6    159.     107.608 1947.      60.323]\n",
      " [     nan   88.5    259.426  232.5    145.6    108.632 1948.      61.122]\n",
      " [     nan   88.2    258.054  368.2    161.6    109.773 1949.      60.171]\n",
      " [     nan   89.5    284.599  335.1    165.     110.929 1950.      61.187]\n",
      " [     nan   96.2    328.975  209.9    309.9    112.075 1951.      63.221]\n",
      " [     nan   98.1    346.999  193.2    359.4    113.27  1952.      63.639]\n",
      " [     nan   99.     365.385  187.     354.7    115.094 1953.      64.989]\n",
      " [     nan  100.     363.112  357.8    335.     116.219 1954.      63.761]\n",
      " [     nan  101.2    397.469  290.4    304.8    117.388 1955.      66.019]\n",
      " [     nan  104.6    419.18   282.2    285.7    118.734 1956.      67.857]\n",
      " [     nan  108.4    442.769  293.6    279.8    120.445 1957.      68.169]\n",
      " [     nan  110.8    444.546  468.1    263.7    121.95  1958.      66.513]\n",
      " [     nan  112.6    482.704  381.3    255.2    123.366 1959.      68.655]\n",
      " [     nan  114.2    502.601  393.1    251.4    125.368 1960.      69.564]\n",
      " [     nan  115.7    518.173  480.6    257.2    127.852 1961.      69.331]\n",
      " [     nan  116.9    554.894  400.7    282.7    130.081 1962.      70.551]]\n"
     ]
    }
   ],
   "source": [
    "# 读入数据 \n",
    "data = genfromtxt(r\"longley.csv\",delimiter=',')\n",
    "print(data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 234.289  235.6    159.     107.608 1947.      60.323]\n",
      " [ 259.426  232.5    145.6    108.632 1948.      61.122]\n",
      " [ 258.054  368.2    161.6    109.773 1949.      60.171]\n",
      " [ 284.599  335.1    165.     110.929 1950.      61.187]\n",
      " [ 328.975  209.9    309.9    112.075 1951.      63.221]\n",
      " [ 346.999  193.2    359.4    113.27  1952.      63.639]\n",
      " [ 365.385  187.     354.7    115.094 1953.      64.989]\n",
      " [ 363.112  357.8    335.     116.219 1954.      63.761]\n",
      " [ 397.469  290.4    304.8    117.388 1955.      66.019]\n",
      " [ 419.18   282.2    285.7    118.734 1956.      67.857]\n",
      " [ 442.769  293.6    279.8    120.445 1957.      68.169]\n",
      " [ 444.546  468.1    263.7    121.95  1958.      66.513]\n",
      " [ 482.704  381.3    255.2    123.366 1959.      68.655]\n",
      " [ 502.601  393.1    251.4    125.368 1960.      69.564]\n",
      " [ 518.173  480.6    257.2    127.852 1961.      69.331]\n",
      " [ 554.894  400.7    282.7    130.081 1962.      70.551]]\n",
      "[ 83.   88.5  88.2  89.5  96.2  98.1  99.  100.  101.2 104.6 108.4 110.8\n",
      " 112.6 114.2 115.7 116.9]\n"
     ]
    }
   ],
   "source": [
    "# 切分数据\n",
    "x_data = data[1:,2:]\n",
    "y_data = data[1:,1]\n",
    "print(x_data)\n",
    "print(y_data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.40875510204081633\n",
      "(16, 50)\n"
     ]
    }
   ],
   "source": [
    "# 创建模型\n",
    "# 生成50个值\n",
    "alphas_to_test = np.linspace(0.001, 1)\n",
    "# 创建模型，保存误差值\n",
    "model = linear_model.RidgeCV(alphas=alphas_to_test, store_cv_values=True)\n",
    "model.fit(x_data, y_data)\n",
    "\n",
    "# 岭系数\n",
    "print(model.alpha_)\n",
    "# loss值\n",
    "print(model.cv_values_.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAX4AAAD8CAYAAABw1c+bAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAAIABJREFUeJzt3Xl8XWd95/HPT/t2tW+2Vq+JHceJ\nHSd2EoYSaCkESsLSGUKaFoaQtoQlFGZalk6npQx9zXSYgSlMahoKGUxYmkDTNkyANhSy2Fh2gtc4\nXuJFtmTJ2mXtur/+ca9tRZGsK/nqXume7/v1ui/de85z7/09Xr7n6DnPOcfcHRERCY60ZBcgIiKJ\npeAXEQkYBb+ISMAo+EVEAkbBLyISMAp+EZGAUfCLiASMgl9EJGAU/CIiAZOR7AKmUl5e7o2Njcku\nQ0Rk0di1a9c5d6+Ipe2CDP7GxkaampqSXYaIyKJhZidibauhHhGRgFHwi4gEjIJfRCRgFPwiIgGj\n4BcRCRgFv4hIwCj4RUQCJmWCPxx2/s8/H+ZnL7UnuxQRkQUtZYI/Lc3Y+rNj/MuLbckuRURkQUuZ\n4AeoKMymrW8o2WWIiCxoKRX8VaEc2nqHk12GiMiCllLBX1mYTVufgl9E5HJSK/hDkaEed092KSIi\nC9aMwW9mdWb2lJkdNLP9ZvbRKdrcbWZ7oo9nzey6CeveZGaHzOyImf1RvDswUWUoh6HRMH3DY/P5\nNSIii1ose/xjwMfdfQ2wBbjfzNZOavMy8Cvuvh74LLAVwMzSgS8DbwbWAndN8d64qSzMBtA4v4jI\nZcwY/O7e4u67o8/7gINAzaQ2z7p7V/TldqA2+vwm4Ii7H3P3EeDbwB3xKn6yitCF4NfMHhGR6cxq\njN/MGoENwI7LNHs/8MPo8xrg1IR1zUzaaEz47PvMrMnMmtrb53YSVmUoB0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GG+x/D0D\nfBb478BQIoubJ7H0+QPAl929C8Ddp74P5eIRS58dKIw+LwLOJLC+uHP3nwGdl2lyB/CwR2wHis1s\nSTxrWIzBXwOcmvC6ObpsyjbuPgb0AGUJqW5+xNLnid5PZI9hMZuxz2a2Aahz939MZGHzKJa/59XA\najN7xsy2m9mbElbd/Iilz/8V+C0zawaeAD6cmNKSZrb/32dtMd6IZao998lTk2Jps5jE3B8z+y1g\nE/Ar81rR/Ltsn80sDfhfwHsTVVACxPL3nEFkuOd1RH6r+7mZrXP37nmubb7E0ue7gK+7+/80s5uB\n/xftc3j+y0uKec+vxbjH3wzUTXhdy6t/9bvYxswyiPx6eLlfrRa6WPqMmf0q8Gngbe4+nKDa5stM\nfQ4B64CfmtlxImOhjy/yA7yx/tv+e3cfdfeXgUNENgSLVSx9fj/wXQB3fw7IIXJNm1QV0//3K7EY\ng38nsMrMlplZFpGDt49PavM48DvR5+8C/sWjR00WqRn7HB32+Gsiob/Yx31hhj67e4+7l7t7o7s3\nEjmu8TZ3b0pOuXERy7/tHxA5kI+ZlRMZ+jmW0CrjK5Y+nwTeAGBma4gEf3tCq0ysx4Hfjs7u2QL0\nuHtLPL9g0Q31uPuYmX0IeJIS0ZVmAAAAs0lEQVTIjICvuft+M/szoMndHwceIvLr4BEie/rvTl7F\nVy7GPv8PoAD4XvQ49kl3f1vSir5CMfY5pcTY5yeBN5rZAWAc+E/u3pG8qq9MjH3+OPBVM/sYkSGP\n9y7mHTkze4TIUF159LjFnwCZAO7+IJHjGLcDR4AB4H1xr2ER//mJiMgcLMahHhERuQIKfhGRgFHw\ni4gEjIJfRCRgFPwiIgGj4BcRCRgFv4hIwCj4RUQC5t8AnG4h4PEsMdsAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x1607b7e1f28>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 画图\n",
    "# 岭系数跟loss值的关系\n",
    "plt.plot(alphas_to_test, model.cv_values_.mean(axis=0))\n",
    "# 选取的岭系数值的位置\n",
    "plt.plot(model.alpha_, min(model.cv_values_.mean(axis=0)),'ro')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([88.11216213])"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model.predict(x_data[2,np.newaxis])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python [default]",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
